package com.ltkj.baseplatform.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ltkj.baseplatform.domain.vo.SerGameDataVo;
import com.ltkj.common.core.domain.R;
import com.ltkj.system.api.RemoteOrderService;
import com.ltkj.system.api.domain.OrderDetailQueryDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.baseplatform.domain.SerGameData;
import com.ltkj.baseplatform.service.ISerGameDataService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 赛事Controller
 * 
 * @author ruoyi
 * @date 2023-09-13
 */
@Api(tags = "赛事")
@RestController
@RequestMapping("/game")
public class SerGameDataController extends BaseController
{
    @Autowired
    private ISerGameDataService serGameDataService;

    @Autowired
    private RemoteOrderService remoteOrderService;

    /**
     * 查询赛事列表
     */
    @ApiOperation("查询赛事列表")
    @RequiresPermissions("baseplatform:game:list")
    @GetMapping("/list")
    public TableDataInfo list(SerGameData serGameData)
    {
        startPage();
        List<SerGameDataVo> list = serGameDataService.selectSerGameDataVoList(serGameData);
        return getDataTable(list);
    }

    /**
     * 导出赛事列表
     */
    @ApiOperation("导出赛事列表")
    @RequiresPermissions("baseplatform:game:export")
    @Log(title = "赛事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SerGameData serGameData)
    {
        List<SerGameData> list = serGameDataService.selectSerGameDataList(serGameData);
        ExcelUtil<SerGameData> util = new ExcelUtil<SerGameData>(SerGameData.class);
        util.exportExcel(response, list, "赛事数据");
    }

    /**
     * 获取赛事详细信息
     */
    @ApiOperation("获取赛事详细信息")
    @RequiresPermissions("baseplatform:game:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serGameDataService.selectSerGameDataVoById(id));
    }

    /**
     * 根据userId和game删除赛事成员
     */
    @ApiOperation("根据userId和game删除赛事成员（订单微服务调用）")
    @GetMapping("/del/member")
    public R delGameMember(@RequestParam("gameId") Long gameId, @RequestParam("userId") Long userId)
    {
        int i = serGameDataService.deleteGameMemberByUserIdAndGameId(userId, gameId);
        if(i > 0){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 新增赛事
     */
    @ApiOperation("新增赛事")
    @RequiresPermissions("baseplatform:game:add")
    @Log(title = "赛事", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SerGameData serGameData)
    {
        return toAjax(serGameDataService.insertSerGameData(serGameData));
    }

    /**
     * 修改赛事
     */
    @ApiOperation("修改赛事")
    @RequiresPermissions("baseplatform:game:edit")
    @Log(title = "赛事", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SerGameData serGameData)
    {
        return toAjax(serGameDataService.updateSerGameData(serGameData));
    }

    /**
     * 删除赛事
     */
    @ApiOperation("删除赛事")
    @RequiresPermissions("baseplatform:game:remove")
    @Log(title = "赛事", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serGameDataService.deleteSerGameDataByIds(ids));
    }

    /**
     * 获取赛事详细信息
     */
    @ApiOperation("获取订单详情")
    @PostMapping("/info")
    public AjaxResult getInfo(@RequestBody OrderDetailQueryDTO queryDTO)
    {
        return success(remoteOrderService.queryOrderDetail(queryDTO));
    }
}
